<?php

namespace api\modules\v1\controllers;

use api\modules\v1\models\shop\GoodsOrderReturn;
use api\modules\v1\models\shop\GoodsOrder;
use yii\helpers\ArrayHelper;
use yii\filters\auth\HttpHeaderAuth;

class GoodsOrderController extends DefaultController
{
    public $modelClass = 'api\modules\v1\models\UserGoodsOrder';


    public function behaviors()
    {
        return ArrayHelper::merge(parent::behaviors(), [
            'authenticator' => [
                'class' =>  HttpHeaderAuth::className(),    //head头部验证
                'header' => 'access-token',
                'optional' => [                     //需要过滤掉不用token参数的方法

                ]
            ]
        ]);
    }

    /**
     * 进入订单页面的数据
     * @return array
     */
    public function actionPreviewInfo() {
        //进入订单页面
        if (\Yii::$app->request->isPost) {
            return (new GoodsOrder())->previewOrder();
        }
    }

    /**
     * 商品订单管理
     * @param int $id
     * @return array
     */
    public function actionInfo ($id = 0) {
        //创建订单
        if (\Yii::$app->request->isPost) {
            return (new GoodsOrder())->createOrder();
        }

        //查看订单
        if (\Yii::$app->request->isGet) {
            return (new GoodsOrder())->getFullInfo($id);
        }
    }

    //我买的
    public function actionList($page = 1, $size = 10, $status = 0) {
        if (\Yii::$app->request->isGet) {
            return (new GoodsOrder())->getList($page, $size, $status);
        }
    }

    //支付订单
    public function actionPay() {
        if (\Yii::$app->request->isPost) {
            return (new GoodsOrder())->toPay();
        }
    }

    //确认收货
    public function actionOrderReceive() {
        if (\Yii::$app->request->isPost) {
            return (new GoodsOrder())->confirmReceive();
        }
    }

    /**
     * 申请退款
     * @return array
     */
    public function actionApplyReturn()
    {
        if (\Yii::$app->request->isPost) {
            return (new GoodsOrderReturn())->OrderApply();
        }
    }

    //取消订单
    public function actionCancel() {
        if (\Yii::$app->request->isPost) {
            return (new GoodsOrder())->cancel();
        }
    }

    public function actionStatus() {
        if (\Yii::$app->request->isGet) {
            return (new GoodsOrder())->getStatusMap();
        }
    }

    // 延迟收货
    public function actionExtendConfirm() {
        if (\Yii::$app->request->isPost) {
            return (new GoodsOrder())->extendConfirm();
        }
    }

    /* ====================== 商户相关 ========================= */

    //卖出的
    public function actionBusinessList($page = 1, $size = 10, $status = 0) {
        if (\Yii::$app->request->isGet) {
            return (new GoodsOrder())->getBusinessList($page, $size, $status);
        }
    }

    //订单详情
    public function actionBusinessInfo($id = 0)
    {
        if (\Yii::$app->request->isGet) {
            return (new GoodsOrder())->getBusinessInfo($id);
        }
    }

    //快递列表
    public function actionExpressList()
    {
        if (\Yii::$app->request->isGet) {
            return (new GoodsOrder())->getExpressList();
        }
    }

    //订单发货
    public function actionDeliver()
    {
        if (\Yii::$app->request->isPost) {
            return (new GoodsOrder())->deliver();
        }
    }

    //商家取消订单
    public function actionShopCancel()
    {
        if (\Yii::$app->request->isPost) {
            return (new GoodsOrder())->shopCancelOrder();
        }
    }

    //退款同意或驳回申请
    public function actionReturnInfo()
    {
        if (\Yii::$app->request->isPost) {
            return (new GoodsOrder())->saveReturnInfo();
        }
    }

    /* ====================== 查看物流 ========================= */
    public function actionShowLogistics() {
        if (\Yii::$app->request->isGet) {
            return (new GoodsOrder())->showLogistics();
        }
    }
}
